package com.hltx.resolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class MyExceptionHandel implements HandlerExceptionResolver{

	@Override
	@ExceptionHandler
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		String returnUrl = "exception/definite";
		
		if(ex instanceof DefiniteException){
			ModelAndView mv =new ModelAndView(returnUrl);
			mv.addObject("message", ex.getMessage());
			return mv;
		}else{
			ModelAndView mv =new ModelAndView(returnUrl);
			mv.addObject("message", "抱歉，您请求的页面没有找到哦！");
			return mv;
		}
		
	}
	
	

}
